package com.rephilo.initializer;

import org.springframework.web.WebApplicationInitializer;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.HandlesTypes;
import java.util.Set;

/**
 * @author rephilo
 */
@HandlesTypes(WebApplicationInitializer.class)
public class MySpringServletContainerInitializer implements ServletContainerInitializer {
    public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException {
        for (Class<?> aClass : set) {
            Class<?>[] interfaces = aClass.getInterfaces();
            for (Class<?> anInterface : interfaces) {
                if (anInterface.equals(WebApplicationInitializer.class)) {
                    try {
                        WebApplicationInitializer webApplicationInitializer = (WebApplicationInitializer) aClass.getDeclaredConstructor().newInstance();
                        webApplicationInitializer.onStartup(servletContext);
                    } catch (Exception e) {

                    }
                }
            }
        }
    }
}
